package com.basksoft.baskreport.demo.service;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;

import javax.sql.DataSource;

import org.apache.commons.dbcp2.BasicDataSourceFactory;

import com.basksoft.report.core.model.datasource.ConnectionProvider;

public class TestConnectionProvider implements ConnectionProvider {
	private static Properties properties = new Properties();
	private static DataSource dataSource;
	// 加载DBCP配置文件
	static {
		properties.put("username", "root");
		properties.put("password", "helpdesk");
		properties.put("driverClassName", "com.mysql.jdbc.Driver");
		properties
                .put("url",
                        "jdbc:mysql://localhost:3306/reportdb?useUnicode=true&characterEncoding=UTF-8&useSSL=false");


		try {
			dataSource = BasicDataSourceFactory.createDataSource(properties);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public Connection getConnection() {
		Connection connection = null;
		try {
			connection = dataSource.getConnection();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return connection;
	}
}
